module Tuscan
  module Iec60584
    module TypeB
      T90_RANGE = 60.0..1820.00
      EMF_RANGE = 0.290..13.821
      extend self

      def emfr_unbound t90
        if t90 < 630.615
          Polynomial.new(
            0.000000000000e+00, -0.246508183460e-03,  0.590404211710e-05, -0.132579316360e-08, 
            0.156682919010e-11, -0.169445292400e-14,  0.629903470940e-18
          ).solve_for t90
        else
          Polynomial.new(
            -0.389381686210e+01,  0.285717474700e-01, -0.848851047850e-04,  0.157852801640e-06, 
            -0.168353448640e-09,  0.111097940130e-12, -0.445154310330e-16,  0.989756408210e-20,
            -0.937913302890e-24 
          ).solve_for t90
        end
      end

      def t90r_guess emf
        if emf < 2.431
          Polynomial.new(
             9.8423321e+01,  6.9971500e+02, -8.4765304e+02, 1.0052644e+03, -8.3345952e+02,
             4.5508542e+02, -1.5523037e+02,  2.9886750e+01, -2.4742860e+00
          ).solve_for emf
        else
          Polynomial.new(
             2.1315071e+02,  2.8510504e+02, -5.2742887e+01,  9.9160804e+00, -1.2965303e+00,
             1.1195870e-01, -6.0625199e-03,  1.8661696e-04, -2.4878585e-06
          ).solve_for emf
        end
      end
    end
  end
end
